package com.xzq.erp.controller;


import com.xzq.erp.aspect.ApiOperationLog;
import com.xzq.erp.domain.dto.PageDTO;
import com.xzq.erp.domain.dto.WarehouseDTO;
import com.xzq.erp.domain.query.AfterSalesServicePageQuery;
import com.xzq.erp.domain.query.WarehousePageQuery;
import com.xzq.erp.domain.vo.IdAndNameVO;
import com.xzq.erp.domain.vo.ProductStockListVO;
import com.xzq.erp.domain.vo.ProductStockVO;
import com.xzq.erp.domain.vo.WarehouseVO;
import com.xzq.erp.service.IWarehouseService;
import com.xzq.erp.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author xzq
 * @since 2025-05-26
 */
@RestController
@RequestMapping("/warehouse")
@Tag(name = "仓库相关接口")
@RequiredArgsConstructor
public class WarehouseController {

    private final IWarehouseService productBrandService;

    @GetMapping
    @Operation(summary = "查询商品仓库列表")
    @ApiOperationLog(description = "查询商品仓库列表")
    public Response<List<IdAndNameVO>> getWarehouseList() {
        return Response.success(productBrandService.getWarehouseList());
    }

    @GetMapping("/list")
    @Operation(summary = "分页查询商品仓库列表")
    @ApiOperationLog(description = "分页查询商品仓库列表")
    public Response<PageDTO<WarehouseVO>> getWarehousePageList(@ParameterObject @Validated WarehousePageQuery query) {
        return Response.success(productBrandService.getWarehousePageList(query));
    }

    @PostMapping
    @Operation(summary = "添加商品仓库")
    @ApiOperationLog(description = "添加商品仓库")
    public Response<Void> addWarehouse(@Validated @RequestBody WarehouseDTO warehouseDTO) {
        productBrandService.addWarehouse(warehouseDTO);
        return Response.success();
    }

    @PutMapping
    @Operation(summary = "修改商品仓库")
    @ApiOperationLog(description = "修改商品仓库")
    public Response<Void> updateWarehouse(@Validated @RequestBody WarehouseDTO warehouseDTO) {
        productBrandService.updateWarehouse(warehouseDTO);
        return Response.success();
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询商品仓库详情")
    @ApiOperationLog(description = "查询商品仓库详情")
    public Response<WarehouseVO> getWarehouseById(@PathVariable Long id) {
        return Response.success(productBrandService.getWarehouseById(id));
    }

    @GetMapping("/{warehouseId}/stock")
    @Operation(summary = "查询商品仓库库存")
    @ApiOperationLog(description = "查询商品仓库库存")
    public Response<List<ProductStockVO>> getWarehouseStock(@PathVariable Long warehouseId) {
        return Response.success(productBrandService.getWarehouseStock(warehouseId));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除商品仓库")
    @ApiOperationLog(description = "删除商品仓库")
    public Response<Void> deleteWarehouse(@PathVariable Long id) {
        productBrandService.removeById(id);
        return Response.success();
    }
}
